#!/usr/bin/env php
<?php
$WackoRoot = GetEnv("TM_BUNDLE_SUPPORT") . "/share/WackoFormatter";
?>
<html>
<head>
<style type="text/css" media="screen">
<?php
$text = file_get_contents($WackoRoot . "/../wakka.css");
print($text);
?>
</style>
</head>
<body>
<?php
$WackoRoot = GetEnv("TM_BUNDLE_SUPPORT") . "/share/WackoFormatter";
require_once("$WackoRoot/WackoFormatter.php");
error_reporting(E_ALL & ~E_NOTICE);

 $filename = $argv[1];
 if(!$filename) $filename = "php://stdin"; // Beg my pardon

 $text = file_get_contents($filename);

 $parser = &new WackoFormatter();

 class CustomConfig extends WackoFormatterConfigDefault
 {
	 var $config = array(
		 "disable_formatters" => 0,
	 );

	 //formatter
	 function Format($text, $formatter, $options) 
	 { 
		 global $WackoRoot;
		 $fullfilename = $WackoRoot."/".$formatter.".php";
		 if (@file_exists($fullfilename))
		 {
			 if (is_array($params)) extract($params, EXTR_SKIP);

			 ob_start();
			 include($fullfilename);
			 $output = ob_get_contents();
			 ob_end_clean();
			 return $output;
		 }
		 return "Formatter ".htmlspecialchars($formatter). " not found";
	 }

	 //preformat action
	 function WrapAction($action) { 
		return "<!--notypo-->\xA1\xA1".$action."\xA1\xA1<!--/notypo-->"; 
	 }

 }
 $Config = &new CustomConfig();
 $parser->SetObject($Config);

 $formatted = $parser->Format($text);

// add typografica & paragrafica
// (if you don`t need them, simply remove next 6 lines)
 //require_once("$WackoRoot/typografica.php");
 //$typo = new typografica( &$Config );
 //$formatted = $typo->correct($formatted);
 //require_once("$WackoRoot/paragrafica.php");
 //$para = new paragrafica( &$Config );
 //$formatted = $para->correct($formatted);

 $formatted = $parser->PostFormat($formatted);
 
 echo $formatted;
?>
</body>
</html>
